package com.zhuiyun.project.api.record.controller;

import com.zhuiyun.project.api.record.entity.CommitRecord;
import com.zhuiyun.project.api.record.entity.MyRecord;
import com.zhuiyun.project.api.record.service.RecordService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;

import com.zhuiyun.project.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class RecordController extends BaseController {

    @Autowired
    RecordService recordService;


    /**
     * @param record
     * @return
     */
    @PostMapping("/saveRecord")
    public CommonResult saveRecord(@RequestBody CommitRecord record){
        int i =  recordService.saveRecord(record);
        if(i>0){
            return CommonResult.ok(i);
        }else{
            return CommonResult.error();
        }
    }

    /**
     *
     * 获取个人提交得记录
     * @param deviceId
     * @return
     */
    @GetMapping("/getRecordByDeviceId")
    public CommonResult getRecordByDeviceId(String deviceId,String type){
            if(ObjectUtils.isNotEmpty(deviceId)){
            return CommonResult.ok(recordService.getRecordByDeviceId(deviceId,type));
        }else{
            return CommonResult.ok();
        }
    }

    /**
     * 用户删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/deleteRecordById")
    public CommonResult deleteRecordById(Integer id,String type){
        if(ObjectUtils.isNotEmpty(id)){
            return CommonResult.ok(recordService.deleteRecordById(id,type));
        }else{
            return CommonResult.ok();
        }
    }
    /**
     * 用户删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/deleteRecordAll")
    public CommonResult deleteRecordAll(int delFlag,String type){
        if(ObjectUtils.isNotEmpty(delFlag)){
            return CommonResult.ok(recordService.deleteRecordAll(delFlag,type));
        }else{
            return CommonResult.ok();
        }
    }

    /**
     * 获取项目下的数据交集
     * @param
     * @return
     */
    @GetMapping("/getDataIntersection")
    public CommonResult getDataIntersection(String type,String optionType,String deviceId){
        return CommonResult.ok(recordService.getDataIntersection(type,optionType,deviceId));
    }
    /**
     * 号码统计
     * @param
     * @return
     */
    @GetMapping("/getDataTotal")
    public CommonResult getDataTotal(String type,String optionType,String deviceId){
        return CommonResult.ok(recordService.getDataTotal(type,optionType,deviceId));
    }

    /**
     * @param record
     * @return
     */
    @PostMapping("/saveMyRecord")
    public CommonResult saveMyRecord(@RequestBody MyRecord record){
        int i =  recordService.saveMyRecord(record);
        if(i>0){
            return CommonResult.ok(i);
        }else{
            return CommonResult.error();
        }
    }

    /**
     * 获取号码的统计次数
     * @param type
     * @return
     */
    @GetMapping("/getResultDataCount")
    public CommonResult getResultDataCount(String type){

        return recordService.getResultDataCount(type);
    }

    /**
     *
     * 在排序类型中按照类型进行统计排序
     * @param type
     * @param optionType
     * @return
     */
    @GetMapping("/getRecordBySort")
    public CommonResult getRecordBySort(String type,int optionType){
        return recordService.getRecordBySort(type,optionType);
    }

    /**
     *
     * Ai的统计
     * @param type
     *  @param limit
     * @return
     */
    @GetMapping("/getAiRecordByType")
    public CommonResult getAiRecordByType(String type,int limit){
        return recordService.getAiRecordByType(type,limit);
    }
}

